var app=angular.module('app',[]);
//自定义元素
app.directive('hello1',function(){
	return {
		restrict:'E',//E代表元素
		replace:'false',//默认值,false.这里会在源码里面显示<hello1><div>Hello Angularjs</div></hello1>
		template:'<div>Hello Angularjs</div>'
	}
});
//自定义元素
app.directive('hello2',function(){
	return {
		restrict:'E',//E代表元素
		replace:'true',//将hello2的内容替换成模版
		template:'<div>Hello Angularjs</div>'
	}
});
//自定义属性
app.directive('hello3',function(){
	return {
		restrict:'A',//A代表属性
		link:function(){
			alert("自定义属性");
		}
	}
});
//自定义class
app.directive('hello4',function(){
	return {
		restrict:'C',//C代表class
		link:function(){
			alert("自定义class");
		}
	}
});
app.controller('appController',function($scope){
	$scope.loadMessage=function(){
		alert("加载数据!");
	}
});

//自定义属性  restrict默认是属性A 可以不写
app.directive('hello5',function(){
	return function(scope,element,attrs){
		element.bind('mouseenter',function(){
			scope.$apply("loadMessage();");
		})
	}
});
//自定义属性   restrict默认是属性A 可以不写
app.directive('hello6',function(){
	return function(scope,element,attrs){
		element.bind('mouseenter',function(){
			scope.$apply(attrs.hello6);
		})
	}
});
app.directive('food',function(){
	return{
		restrict:'E',
		controller:function($scope){
			$scope.foods=[];
			this.addApple=function(){
				$scope.foods.push('apple');
			}
			this.addOrange=function(){
				$scope.foods.push('orange');
			}
			this.addBannana=function(){
				$scope.foods.push('bannana');
			}
		},
		link:function(scope,element,attrs){
			element.bind('mouseenter',function(){
				console.log(scope.foods);
			});
			
		}
	}
});
app.directive('apple',function(){
	return{
		require:'food',
		link:function(scope,element,attrs,foodCtrl){
			foodCtrl.addApple();
		}
	}
});
app.directive('orange',function(){
	return{
		require:'food',
		link:function(scope,element,attrs,foodCtrl){
			foodCtrl.addOrange();
		}
	}
});
app.directive('bannana',function(){
	return{
		require:'food',
		link:function(scope,element,attrs,foodCtrl){
			foodCtrl.addBannana();
		}
	}
});


